package scct.jiangjiale.utility;

import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;

public class dbUtilis {
    private static String dbDriver="com.mysql.cj.jdbc.Driver";

    private static String dbUrl =
            "jdbc:mysql://localhost:3306/catering management system?characterEncoding=UTF-8&useSSL=false";
            private static String name="root";
            private static String pass="123456";
            public static Connection getConnection(){
                Connection conn;
                try {
                    Class.forName(dbDriver);
                   conn= DriverManager.getConnection(dbUrl, name, pass);
                } catch (ClassNotFoundException e) {
                    throw  new RuntimeException(e);
                } catch (SQLException e) {
                    throw new RuntimeException(e);
                }

                return conn;
            }
    public static void closeConnection(Connection con) throws Exception {
        if (con != null) {
            try {
                con.close();
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }
        }
    }


}
